using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

namespace HPIT.Shop.Services.Entities
{
    public partial class ShopContext : DbContext
    {
        public ShopContext()
            : base("name=ShopContext")
        {
        }

        public virtual DbSet<category> category { get; set; }
        public virtual DbSet<information> information { get; set; }
        public virtual DbSet<Logn> Logn { get; set; }
        public virtual DbSet<property> property { get; set; }
        public virtual DbSet<Receiving> Receiving { get; set; }
        public virtual DbSet<TBUser> TBUser { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<category>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<category>()
                .HasMany(e => e.information)
                .WithOptional(e => e.category)
                .HasForeignKey(e => e.Idcategory);

            modelBuilder.Entity<information>()
                .Property(e => e.TradeName)
                .IsUnicode(false);

            modelBuilder.Entity<information>()
                .Property(e => e.marketPrice)
                .HasPrecision(18, 0);

            modelBuilder.Entity<information>()
                .Property(e => e.goodsUnit)
                .IsUnicode(false);

            modelBuilder.Entity<information>()
                .Property(e => e.shopPrice)
                .HasPrecision(18, 0);

            modelBuilder.Entity<information>()
                .Property(e => e.goodsDesc)
                .IsUnicode(false);

            modelBuilder.Entity<Logn>()
                .Property(e => e.MobileNumber)
                .IsUnicode(false);

            modelBuilder.Entity<Logn>()
                .Property(e => e.UserName)
                .IsUnicode(false);

            modelBuilder.Entity<Logn>()
                .Property(e => e.Password)
                .IsUnicode(false);

            modelBuilder.Entity<property>()
                .Property(e => e.URL)
                .IsUnicode(false);

            modelBuilder.Entity<property>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<property>()
                .HasMany(e => e.information)
                .WithRequired(e => e.property)
                .HasForeignKey(e => e.gallery)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Receiving>()
                .Property(e => e.consignee)
                .IsUnicode(false);

            modelBuilder.Entity<Receiving>()
                .Property(e => e.MobileNumber)
                .IsUnicode(false);

            modelBuilder.Entity<Receiving>()
                .Property(e => e.Address)
                .IsUnicode(false);

            modelBuilder.Entity<TBUser>()
                .Property(e => e.NickName)
                .IsUnicode(false);

            modelBuilder.Entity<TBUser>()
                .Property(e => e.Avatar)
                .IsUnicode(false);

            modelBuilder.Entity<TBUser>()
                .HasMany(e => e.Receiving)
                .WithOptional(e => e.TBUser)
                .HasForeignKey(e => e.AddressId);
        }
    }
}
